﻿namespace FiftyOne.Foundation.Mobile.Detection.Wurfl.Configuration
{
    using FiftyOne.Foundation.Mobile.Configuration;
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Web.Configuration;

    internal static class Manager
    {
        private static WurflSection _configurationSection = ((WurflSection) WebConfigurationManager.GetWebApplicationSection("fiftyOne/wurfl"));

        internal static StringCollection CapabilitiesWhiteList
        {
            get
            {
                StringCollection strings = new StringCollection();
                foreach (CapabilityElement element in _configurationSection.CapabilitiesWhiteList)
                {
                    strings.Add(element.CapabilityName);
                }
                return strings;
            }
        }

        internal static bool Enabled
        {
            get
            {
                return (((_configurationSection != null) && _configurationSection.ElementInformation.IsPresent) && !string.IsNullOrEmpty(_configurationSection.WurflFilePath));
            }
        }

        internal static FiftyOne.Foundation.Mobile.Detection.Wurfl.Configuration.NewDeviceDetail NewDeviceDetail
        {
            get
            {
                string newDeviceDetail = _configurationSection.NewDeviceDetail;
                if ((newDeviceDetail != null) && (newDeviceDetail == "maximum"))
                {
                    return FiftyOne.Foundation.Mobile.Detection.Wurfl.Configuration.NewDeviceDetail.Maximum;
                }
                return FiftyOne.Foundation.Mobile.Detection.Wurfl.Configuration.NewDeviceDetail.Minimum;
            }
        }

        internal static string NewDevicesURL
        {
            get
            {
                return _configurationSection.NewDevicesURL;
            }
        }

        internal static bool UseActualDeviceRoot
        {
            get
            {
                return _configurationSection.UseActualDeviceRoot;
            }
        }

        internal static string WurflFilePath
        {
            get
            {
                return Support.GetFilePath(_configurationSection.WurflFilePath);
            }
        }

        internal static string[] WurflPatchFiles
        {
            get
            {
                List<string> list = new List<string>();
                foreach (PatchConfigElement element in _configurationSection.WurflPatches)
                {
                    if (element.Enabled)
                    {
                        list.Add(Support.GetFilePath(element.FilePath));
                    }
                }
                return list.ToArray();
            }
        }
    }
}

